package com.example.server.controller;

import com.example.server.entity.Order;
import com.example.server.entity.Product;
import com.example.server.entity.User;
import com.example.server.service.OrderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("order")
public class OrderController extends BaseController{
    private final OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @PostMapping("create")
    @ResponseBody
    private boolean create(@RequestBody Order order){
        orderService.create(order);
        return true;
    }

    @GetMapping("queryByUid")
    @ResponseBody
    private List<Order> list(@RequestParam BigInteger uid){
        List<Order> list = orderService.queryList("queryByUid",uid);
        return list;
    }

    @GetMapping("queryAll")
    @ResponseBody
    private List<Order> queryAll(){
        return orderService.queryAll();
    }

    @GetMapping("queryById")
    @ResponseBody
    private Order queryById(@RequestParam BigInteger oid){
        Order order = orderService.queryOne("queryById",oid);
        return order;
    }

    @DeleteMapping("removeById")
    @ResponseBody
    private boolean removeById(@RequestBody Map<String, BigInteger> map) {
        BigInteger oid = map.get("oid");
        orderService.removeById(oid);
        return true;
    }
}
